package thread.java20230109;

import java.util.concurrent.atomic.AtomicInteger;

public class Demo46 {
    private static AtomicInteger count = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 5_0000; i++) {
                count.getAndIncrement();//i++
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 5_0000; i++) {
                count.getAndIncrement();
            }
        });

        t1.start();
        t2.start();
        //打印count值的时候, 需要等待t1 和t2 执行完
        t1.join();
        t2.join();

        System.out.println(count);

    }
}
